package com.hzw.subject.domain.handler.subject;

import com.hzw.subject.common.enums.IsDeletedFlagEnum;
import com.hzw.subject.common.enums.SubjectInfoTypeEnum;
import com.hzw.subject.domain.convert.RadioSubjectConverter;
import com.hzw.subject.domain.entity.SubjectAnswerBO;
import com.hzw.subject.domain.entity.SubjectInfoBO;
import com.hzw.subject.domain.entity.SubjectOptionBO;
import com.hzw.subject.infra.basic.entity.SubjectRadio;
import com.hzw.subject.infra.basic.service.SubjectRadioService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.LinkedList;
import java.util.List;

/**
 * @author ：xx
 * @description：TODO
 * @date ：2025/2/20 15:50
 */
@Component
public class RadioTypeHandler implements SubjectTypeHandler{
    @Resource
    private SubjectRadioService subjectRadioService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.RADIO;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {

        //单选题目的插入
        List<SubjectRadio> subjectRadioList = new LinkedList<>();
        subjectInfoBO.getOptionList().forEach(option -> {
            SubjectRadio subjectRadio = RadioSubjectConverter.INSTANCE.convertBoToInfo(option);
            subjectRadio.setSubjectId(subjectInfoBO.getId());
            subjectRadio.setOptionConnect(option.getOptionContent());
            subjectRadio.setIsDeleted(IsDeletedFlagEnum.UN_DELEETED.getCode());
            subjectRadioList.add(subjectRadio);
        });
        subjectRadioService.batchinsert(subjectRadioList);
    }

    @Override
    public SubjectOptionBO query(int subjectId) {
        return null;
    }
}
